/// 动态数据模型
class PostModel {
  final String postId;
  final String userId;
  final String content;
  final List<String> mediaUrls; // 资源文件URL列表（图片或视频）
  final List<String> videoThumbnails; // 视频封面图URL列表，与mediaUrls中的视频按索引对应
  final DateTime publishTime;
  final int favoriteCount;
  final int commentCount;
  final List<String> favoritedUserIds; // 收藏用户ID列表

  const PostModel({
    required this.postId,
    required this.userId,
    required this.content,
    required this.mediaUrls,
    required this.videoThumbnails,
    required this.publishTime,
    required this.favoriteCount,
    required this.commentCount,
    required this.favoritedUserIds,
  });

  /// 获取指定索引的媒体类型（图片或视频）
  bool isVideoAtIndex(int index) {
    if (index >= mediaUrls.length) return false;
    return index < videoThumbnails.length && videoThumbnails[index].isNotEmpty;
  }

  /// 获取指定索引的视频封面图
  String? getVideoThumbnailAtIndex(int index) {
    if (!isVideoAtIndex(index)) return null;
    return videoThumbnails[index];
  }

  /// 复制并修改模型
  PostModel copyWith({
    String? postId,
    String? userId,
    String? content,
    List<String>? mediaUrls,
    List<String>? videoThumbnails,
    DateTime? publishTime,
    int? favoriteCount,
    int? commentCount,
    List<String>? favoritedUserIds,
  }) {
    return PostModel(
      postId: postId ?? this.postId,
      userId: userId ?? this.userId,
      content: content ?? this.content,
      mediaUrls: mediaUrls ?? this.mediaUrls,
      videoThumbnails: videoThumbnails ?? this.videoThumbnails,
      publishTime: publishTime ?? this.publishTime,
      favoriteCount: favoriteCount ?? this.favoriteCount,
      commentCount: commentCount ?? this.commentCount,
      favoritedUserIds: favoritedUserIds ?? this.favoritedUserIds,
    );
  }
}
